package com.huangwei.service.impl;

import com.huangwei.dao.CarBandDao;
import com.huangwei.dao.SaleServiceShopDao;
import com.huangwei.model.CarBand;
import com.huangwei.model.SaleServiceShop;
import com.huangwei.service.SaleServiceShopService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

@Service
public class SaleServiceShopServiceImpl implements SaleServiceShopService {
    @Resource
    SaleServiceShopDao saleServiceShopDao;
    @Resource
    CarBandDao carBandDao;
    @Override
    public SaleServiceShop getOneSaleServiceShopById(int saleServiceShopId) {
        try {
            return saleServiceShopDao.queryOne(saleServiceShopId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<SaleServiceShop> getSaleServiceShopsByBand(Integer carBandId) {
        try {
            return saleServiceShopDao.queryByBand(carBandId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<SaleServiceShop> getAllSaleServiceShops() {
        try {
            return saleServiceShopDao.queryAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public List getSaleServiceShopList() {
        List resultList = new LinkedList();
        resultList.add(getAllSaleServiceShops());
        List<CarBand> carBandList = carBandDao.queryAll();
        carBandList.stream()
                .forEach(carBand -> {
                    resultList.add(getSaleServiceShopsByBand(carBand.getCarBandId()));
                });
        return resultList;
    }
}
